"""
This class provides a way to create patterns, an alternative to regular expressions
that make it easier to match blocks of text.

Copyright (c) 2009 Christopher Hesse
http://code.google.com/p/python-expect/
"""


class Match(object):
    def __nonzero__(self):
        pass


class Token(object):
    
    def __init__(self, type, value):
        self.type = type
        self.value = value


class TextPattern(object):
    """
    TODO: this will be a stub that accepts only * as an operator in patterns
    TODO: proper parser + BNF for patterns
    TODO: handling of special characters
    
    *: match any series of 1 or more non-whitespace characters
    
    Future (work in progress):
    %(name): capture match
    $name: match against variable contents (string or regular expression)
    %(name)$name:
    TABLE>
    ROW>
    REPEAT>
    ANY> 
    
    Example:
        p = Pattern("string * string")
        result = p.search("string string string")
        assert(result)
    """
    
    def __init__(self, pattern):
        self.pattern = pattern
        self.compile()
    
    @staticmethod
    def _tokenize(self, pattern):
        result = []
        # for char in pattern:
        #     result.append()
        # Token('STRING', "string")
        # Token('STAR', "*")
        return result
        
    def compile(self):
        """
        Convert the pattern into a compiled internal representation
        """
        tokens = self._tokenize(self.pattern)
    
    def search(self, string):
        pass